import {httpUtil} from '@/core/HttpUtil';

const itemApiBaseUrl= '<#if package.ModuleName?default("")?trim?length gt 1>/${package.ModuleName}</#if>/${table.entityPath}';

export default {
    /**
     * 所有列表
     * @param bean
     * @returns {*}
     */
    list: function ({bean} = {}) {
        let params = {
            beanJson: bean ? JSON.stringify(bean) : null,
        };
        return httpUtil.get({
            url: itemApiBaseUrl + '/list',
            params: params,
        });
    },

    /**
     * 列表分页
     * @param page
     * @param pageSize
     * @param bean
     * @returns {*}
     */
    page: function ({page, pageSize, bean}) {
        let params = {
            page: page,
            pageSize: pageSize,
            beanJson: bean ? JSON.stringify(bean) : null,
        };
        return httpUtil.get({
            url: itemApiBaseUrl + '/page',
            params: params,
        });
    },

    /**
     * 获取一个记录
     * @param uuid
     * @returns {*}
     */
    selectOne: function ({uuid}) {
        let params = {
            uuid: uuid,
        };
        return httpUtil.get({
            url: itemApiBaseUrl + '/selectOne',
            params: params,
        });
    },

    /**
     * 添加一个记录
     * @param bean
     * @returns {*}
     */
    add: function ({bean} = {}) {
        let params = {
            beanJson: bean ? JSON.stringify(bean) : null,
        };
        return httpUtil.get({
            url: itemApiBaseUrl + '/add',
            params: params,
        });
    },

    /**
     * 修改
     * @param bean
     * @returns {*}
     */
    update: function ({bean} = {}) {
        let params = {
            beanJson: bean ? JSON.stringify(bean) : null,
        };
        return httpUtil.get({
            url: itemApiBaseUrl + '/update',
            params: params,
        });
    },

    /**
     * 删除一个记录
     * @param bean
     * @returns {*}
     */
    delete: function ({uuid}) {
        let params = {
            uuid: uuid,
        };
        return httpUtil.get({
            url: itemApiBaseUrl + '/delete',
            params: params,
        });
    },
};